<?php if ( ! defined('WDK_PATH')) exit('No direct script access allowed');
require_once BASE_PATH.'app/controller.php';
class Scrapped extends Controller
{
	function __construct()
	{
		parent::__construct();
		$this->_init();
	}
	
	protected function _init() 
	{
		parent::_loginCheck();
	}
	
	public function index()
	{
		/*****************************************************************************************************************************
		 * BASIC VARS
		*****************************************************************************************************************************/
		$assign_data = array();
		/****************************************************************************************************************************/
		try 
		{
			$assign_data['json'] = $this->json(true);
		}
		catch(WException $e)
		{
			parent::_error($e);
		}
		/*****************************************************************************************************************************
		 * RESULT
		*****************************************************************************************************************************/	
		parent::_view($assign_data);
		/****************************************************************************************************************************/
	}
	
	public function json($return=false)
	{
		/*****************************************************************************************************************************
		 * POST PARAMS..
		*****************************************************************************************************************************/
		$page	= (int) get('page', 1);
		/*****************************************************************************************************************************
		 * BASIC VARS
		*****************************************************************************************************************************/
		$listsize		= 10;
		$pagesize		= 10;
		$lm = Wdk::get('UserScrapManager');
		$lists = array();
		$where = array("`us`.`fk_user_seq` = {$this->session['user_seq']}");
		$assign_data = array('listsize'=>$listsize,'pagesize'=>$pagesize);
		/****************************************************************************************************************************/
		try
		{
			$lm['listsize'] = $listsize;
			$lm['page'] = $page;
			$lm['where'] = $where;
			$lm->load();
			foreach($lm['lists'] as $idx=>$list)
			{
				$data = array(	'no'			=>	$lm['total'] - ($page-1)*$listsize - $idx,
								'seq'			=>	$list['user_scrap_seq'],
								'user_nick'		=>	$list['user_nick'],
								'bbs_name'		=>	$list['bbs_name'],
								'bbs_id'		=>	$list['bbs_id'],
								'post_seq'		=>	$list['fk_post_seq'],
								'post_title'	=>	$list['post_title'],
								'insert_time'	=>	$list['user_scrap_insert_time_str']
							);
				array_push($lists, $data);
			}
			$assign_data['total'] = $lm['total']; 
			$assign_data['lists'] = $lists;
		}
		catch(NoRecordException $e)
		{
			$assign_data['total'] = 0;
			$assign_data['lists'] = array();
		}
		catch(WException $e)
		{
			$assign_data['error'] = true;
			$assign_data['msg'] = "Error";
		}
		/*****************************************************************************************************************************
		 * RESULT
		*****************************************************************************************************************************/
		return parent::_json($assign_data, $return);
		/****************************************************************************************************************************/
	}
}